package com.coder520.mamabike.b.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.coder520.mamabike.b.R;
import com.coder520.mamabike.b.presenter.PositionChoosePresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by zhongyanli on 2017/10/14.
 */

public class PositionChooseActivity extends BaseActivity<PositionChoosePresenter> {
    public static final String EXTRA_POINT = "extra_point";

    @BindView(R.id.mapview_main)
    MapView mapviewMain;
    private BaiduMap mBaiduMap;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.postion_choose_activity);
        ButterKnife.bind(this);
        mBaiduMap = mapviewMain.getMap();
        LatLng centPt = new LatLng(30.611939D, 104.151288D);
        MapStatus mapStatus = new MapStatus.Builder()
                .target(centPt)
                .zoom(16)
                .build();
        MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
        mBaiduMap.setMapStatus(mapStatusUpdate);
    }

    @Override
    protected PositionChoosePresenter createPresenter() {
        return new PositionChoosePresenter(this);
    }


    @OnClick(R.id.btn_ok)
    public void onViewClicked() {
        LatLng center = mBaiduMap.getMapStatus().target;
        Intent intent = new Intent();
        intent.putExtra(EXTRA_POINT, center);
        setResult(RESULT_OK, intent);
        finish();
    }
}
